<!-- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> -->

<!-- 通用底部文件 -->
</body>

</html>
<!--扩展脚本及插件-->
<!-- 你的HTML代码 -->
<script src="statics/layui.all.js"></script>

<script src="statics/js/base64.min.js"></script>
<%--<script src="statics/modules/formSelects-v4/formSelects-v4.js"></script>
<script src="statics/modules/treetablelay/treetable.js"></script>--%>

<%--<link rel="stylesheet" href="http://localhost:8080/erp/statics/css/modules/formSelects-v4.css" />--%>
<script>
    //将图片下载到服务器上
    //如：url:/upload/4/admin/1616506691024/chineselogo/1616506691024.jpg
    function onLine2(url){
        $.ajax({
            url: 'ftp/onLine2?pathString='+url,
            type: 'GET',
            async: false, // 同步
            success: function (date) {
            },
        });
    }

    //获取url get形式传过来的参数
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for(var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable) {
            return pair[1];
        }
    }
    return("");
}
//时间戳转为js实现时间戳转化为YYYY-MM-DD hh:mm:ss
function timestampToTime(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
    var D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
    var h = (date.getHours() < 10 ? '0'+date.getHours():date.getHours())+ ':';
    var m = (date.getMinutes() < 10 ? '0'+date.getMinutes():date.getMinutes()) + ':';
    var s = date.getSeconds() < 10 ? '0'+date.getSeconds():date.getSeconds();
    return Y+M+D+h+m+s;
}
/**
 * 组装图片回显路径
 */
function getFtpPath(ftpPath,fileName){

    return "ftp/downloadimg"+"?pathname="+ftpPath+"&filename="+fileName;
}
//获取字典
//同步访问
function getdictionary(dl,xl) {
    var obj=[];
    $.ajax({
        type : 'POST',
        //  url : 'resource/getTree',
        data: {"type":dl,"lx":xl},
        url:'dictionary2/getValues',
        dataType:"json",
        // contentType: 'application/json',
        async:false,
        success : function (da) {
            if(da.status==200 ){
                obj=da.data;
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
    return obj;
}
//异步访问字典
    function getdictionaryF(dl,xl) {
        var obj=[];
        $.ajax({
            type : 'POST',
            //  url : 'resource/getTree',
            data: {"type":dl,"lx":xl},
            url:'dictionary2/getValues',
            dataType:"json",
            // contentType: 'application/json',
            async:true,
            success : function (da) {
                if(da.status==200 ){
                    obj=da.data;
                }
            },
            error: function(data) {
                // layer.msg("获取失败!");
            }
        });
        return obj;
    }
//获取报表url前缀
function  getReportUrl() {
    var url=getdictionary(6,54);
    return url[1].name;
}

//加载下载文件,此方法作废，启用downFileLoadNew
function downFileLoad(fileName) {
    let xhr = new XMLHttpRequest();
    let url = "wjinfo/downloadfile2?filename=" + fileName;
    xhr.open('GET', url, true);
    xhr.responseType = "blob";
    xhr.send(null);

    xhr.onload = function() {
        let aName = xhr.getResponseHeader('Content-Disposition').split('=')[1];
        const data = xhr.response;
        const a = document.createElement('a');
        const blob = new Blob([data],{ type: 'application/force-download' });
        const blobUrl = window.URL.createObjectURL(blob);
        downFileload2(blobUrl,aName) ;
    }
}
//加载下载文件
    function downFileLoadNew(fileName,filePath) {
        window.sessionStorage.setItem("fileName",fileName);
        var xhr = new XMLHttpRequest();
        var url = "wjinfo/downloadfile2?filename=" + filePath;
        xhr.open('GET', url, true);
        xhr.responseType = "blob";
        xhr.send(null);

        xhr.onload = function() {
            var aName= window.sessionStorage.getItem("fileName")
            // var aName = xhr.getResponseHeader('Content-Disposition').split('=')[1];

            const data = xhr.response;
            const a = document.createElement('a');
            const blob = new Blob([data],{ type: 'application/force-download' });
            const blobUrl = window.URL.createObjectURL(blob);
            downFileload2(blobUrl,aName) ;
        }
    }
//在线预览，入参：附件在表中存放的路径
function onLineFile(url) {
   // var url=data.path;
    $.ajax({
        url: 'ftp/onLineonLine?pathString='+url,
        type: 'GET',
        async: false, // 同步
        success: function (data) {
            openWindowLook(data.data);
        },
    });
}

//预览服务默认和erp服务配置同一台服务器，端口号默认8012
function openWindowLook(fileName) {
    //此处为调用open方法打开预览,例如：url：/upload/aaa.docx
    var splits=$("base")[0].baseURI.split(":");
    var serverIp=splits[0]+":"+splits[1];
    if(serverIp.endsWith("/erp/")){
        serverIp=serverIp.substr(0,serverIp.length-5);
    }
    var fileUrl=serverIp+":8012/demo/"+fileName;
   // http://127.0.0.1:8012/demo/1234.docx
    window.open(serverIp + ':8012/onlinePreview?url='+encodeURIComponent(Base64.encode(fileUrl)));
}

//下载文件
function downFileload2(blobUrl,aName){
  /*  const a = document.createElement('a');
    a.style.display = 'none';
    a.download = decodeURIComponent(aName);
    a.download=a.download.substring(a.download.lastIndexOf("/")+1);//取文件字
    a.href = blobUrl;
    a.click();*/
    //document.body.removeChild(a);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.download = decodeURIComponent(aName);
    a.href = blobUrl;
    a.click();
}
//获取当前登录人的管理权限，即其所管理的员工,code:字典中所配置的管理者所对应的用户组编码,model:哪个模块,type:哪个类型，即是操作员还是业务员
function getManageRule(code,model,lx){

  var userTree={};
    $.ajax({
        type : 'get',
        //  url : 'resource/getTree',
        data: {"code":code,model:model,lx:lx},
        url:'department/selectUserTree',
        dataType:"json",
        // contentType: 'application/json',
        async:true,
        success : function (da) {
            if(da.status==200 ){
                userTree=da.data;
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
  return userTree;

}

    //获取当前用户的部门及人员结构树(只包含在职人员)
    function getCurrentDepartmentUser() {
        let userTree = {};
        $.ajax({
            type: 'get',
            url: 'department/getServingOfficersDepartmentTree',
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.status == 200) {
                    userTree = data.data;
                }
            },
            error: function (data) {
            }
        });
        return userTree;

    }

    //获取当前用户所管理的部门(所有人员)
    function getAllUserDepartmentTree() {
        let userTree = {};
        $.ajax({
            type: 'get',
            url: 'department/getCurrentDepartmentUser',
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.status == 200) {
                    userTree = data.data;
                }
            },
            error: function (data) {
            }
        });
        return userTree;

    }

    //获取当前用户所属部门树
    function getCurrentUserDepartmentTree() {
        let userTree = {};
        $.ajax({
            type: 'get',
            url: 'department/getCurrentUserDepartmentTree',
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.status == 200) {
                    let dat = data.data;
                    let obj = {};
                    obj.id = dat.id;
                    obj.code = dat.code;
                    obj.name = dat.name;
                    obj.desc = dat.desc;
                    obj.createTime = dat.createTime;
                    obj.creator = dat.creator;
                    obj.pid = dat.pid;
                    obj.companyCode = dat.companyCode;
                    obj.users = dat.users;
                    obj.list = initDataTree(dat.list);
                    obj.children = obj.list;
                    obj.title = obj.name;
                    obj.field = "";

                    userTree = obj;
                }
            }
        });
        return userTree;
    }

    function initDataTree(data) {
        let object = [];
        for (var i = 0; i < data.length; i++) {
            let obj = {};
            obj.id = data[i].id;
            obj.code = data[i].code;
            obj.name = data[i].name;
            obj.desc = data[i].desc;
            obj.createTime = data[i].createTime;
            obj.creator = data[i].creator;
            obj.companyCode = data[i].companyCode;
            obj.users = data[i].users;
            obj.title = obj.name;
            obj.field = "";
            if (data[i].list != null) {
                obj.list = initDataTree(data[i].list);
            }
            obj.children = obj.list;
            object.push(obj);
        }
        return object;
    }

    //判断当前登陆人是否具有此权限,具有时返回false
    function getAllRolesByCurr(role) {
        var AllRole=JSON.parse(window.sessionStorage.getItem("AllRole"));//权限；
        for(var i=0;i<AllRole.length;i++){
            if(AllRole[i] != null && AllRole[i].code==role){
                return false;
            }
        }
        return true;
    }

    //防止重复提交
    function preventDuplicateSubmissions(){
        layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            time: 2*1000
        });
    }

// 框架脚本设置
  layui.config({
    base: 'statics/'  //静态资源所在路径
  }).extend({
      index: 'lib/index' //主入口模块
      ,treetable: 'modules/treetablelay/treetable'
      ,tableEdit:'modules/tableEdit/tableEdit'
      ,dropdown:'modules/dropdown/dropdown'
      ,selectInput:'modules/selectInput/selectInput'
      ,excel:'modules/layuiExts/excel',
  });
      //.use(['index', "common", "element","layer", "util","table", "jquery", "senior", "echarts", "sample", "tree","laypage"]);

</script> 
 